<%--
  Created by IntelliJ IDEA.
  User: ln
  Date: 2021/2/26
  Time: 10:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //获取项目名称
    String path = request.getContextPath();
    //获取: 协议://服务器名称:/端口号+ path +"/"
    //http://localhost:8080/Demo18_StuAndTeacher/  --->main.jsp
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>分数</title>
    <base href="<%=basePath%>">
    <script src="jquery/jquery-1.8.3.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css" >
    <script src="layui/layui.js"></script>
</head>
<body>

<input class="layui-input-block" name="courseName" id="name" placeholder="课程名">
<button class="layui-btn" id="btn">查询</button>

<table id="demo" lay-filter="test"></table>

</body>

<script>
    layui.use('table', function(){
        var table = layui.table;

        //第一个实例
        tableResult = table.render({
            elem: '#demo'   //获取table标签对象，添加数据
            ,url: 'ServletScore' //获取数据的接口（srvlet)
            ,page: true //开启分页
            ,limit:10
            ,size:"lg"
            ,toolbar:true
            ,cols: [[ //表头
                {field: 'courseName', title: '科目', fixed: 'left',align:"center"}
                ,{field: 'courseCredit', title: '学分',align:"center"}
                ,{field: 'courseHours', title: '学时' ,align:"center"}
                ,{field: 'courseTeacher', title: '任课老师',align:"center"}
                ,{field: 'major', title: '专业',align:"center"}
                ,{field: 'courseDate', title: '开课时间',align:"center", width: 180 ,templet: "<div>{{layui.util.toDateString(d.courseDate, 'yyyy-MM-dd')}}</div>" }
                ,{field: 'scoreGrade', title: '成绩', sort: true,align:"center"}
            ]]
        });

    });


    $("#btn").click(function () {
        var value = $("#name").val();
        if(value!=null){
            tableResult.reload({
                url:"ServletCourse",
                where:{ //这是请求servlet的参数，多个餐宿用逗号隔开
                    courseName:value
                    // ,username:"tom

                },
                page:{//初始化page数，保证查询数据是从第一页开始
                    curr:1

                }




            })

        }

    });

</script>

</html>
